#include "Splines.h"
#include <fstream>

double f(double x);
double df(double x);

int main(int argc, char *argv[])
{
    Complete_cubic_spline<double> C;
    int N;
    std::vector<double> knots;
    std::vector<double> ic;
    double dfa;
    double dfb;
    std::cin >> N;
    C.set_N(N);
    knots.resize(N);
    ic.resize(N);
    for(int i = 0; i < N; i++)
    {
	knots[i] = -1.0 + i*2.0/double(N-1);
	ic[i] = f(knots[i]);
    }
    dfa = df(knots[0]);
    dfb = df(knots[N-1]);
    C.set_knots(knots);
    C.set_boundary_condition(dfa, dfb);
    C.set_interpolation_condition(ic);
    C.set_derivatives();
    C.set_lambda();
    C.set_mu();
    double x[101];
    double p;
    
    std::ofstream output("spline.m");
    output << "x = [" ;
    for(int i = 0; i < 101; i++)
    {
	x[i] = -1.0 + i*2.0/100.0;
	output << x[i] << " ";
    }
    output << "];" << std::endl;
    output << "p = [";
    for(int i = 0; i < 101; i++)
    {
	p = C.Spline_generator(x[i]);
	output << p << " ";
    }
    output << "];" << std::endl;
    output << "plot(x, p);" << std::endl;
    output.close();

    return 0;
};

double f(double x)
{
    return 1.0/(1.0+25.0*x*x);
};

double df(double x)
{
    return -(50.0*x)/(1.0+25.0*x*x)*(1.0+25.0*x*x);
};

